<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
    <head>
        <th:block th:include="include :: header('租户列表')"/>
    </head>
    <body class="gray-bg">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>租户名称：</label>
                                    <input type="text" name="tenantName"/>
                                </li>
                                <li>
                                    <label>租户编号：</label>
                                    <input type="text" name="tenantNo"/>
                                </li>
                                <li>
                                    <label>租户状态：</label>
                                    <select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                                th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li class="select-time">
                                    <label style="width: 100px;">系统运行日：</label>
                                    <input type="text" class="time-input" id="startTime" name="startDate"/>
                                </li>
                                <li class="select-time">
                                    <label style="width: 100px;">系统到期日：</label>
                                    <input type="text" class="time-input" id="endTime" name="endDate"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                            class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                            class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="platform:tenant:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
                       shiro:hasPermission="platform:tenant:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-warning" onclick="$.table.exportExcel()"
                       shiro:hasPermission="platform:tenant:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
        <th:block th:include="include :: footer"/>
        <th:block th:include="include :: layout-latest-js"/>
        <script th:inline="javascript">
            var editFlag = [[${@permission.hasPermi('platform:tenant:edit')}]];
            var removeFlag = [[${@permission.hasPermi('platform:tenant:remove')}]];
            var prefix = ctx + "platform/tenant";

            $(function () {
                var options = {
                    url: prefix + "/list",
                    createUrl: prefix + "/add",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove",
                    exportUrl: prefix + "/export",
                    modalName: "租户",
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'id',
                            title: 'id',
                            visible: false
                        },
                        {
                            field: 'tenantName',
                            title: '租户名称'
                        },
                        {
                            field: 'tenantNo',
                            title: '租户编号'
                        },
                        {
                            visible: editFlag == 'hidden' ? false : true,
                            title: '租户状态',
                            align: 'center',
                            formatter: function (value, row, index) {
                                return statusTools(row);
                            }
                        },
                        {
                            field: 'logoUrl',
                            title: 'logo',
                            formatter: function (value, row, index) {
                                if ($.common.isNotEmpty(value)) {
                                    // return '<img style="width: 100px;height: 100px;" src="' + ctx + value + '">';
                                    //(${#strings.isEmpty(user.avatar)}) ? @{/img/profile.jpg} : @{${user.avatar}}
                                    return '<img style="width: 100px;height: 100px;" src="' + value + '">';
                                }
                                return '<img style="width: 100px;height: 100px;" src="' + ctx + "huan.png" + '">';
                            }
                        },
                        {
                            field: 'startDate',
                            title: '系统运行日'
                        },
                        {
                            field: 'endDate',
                            title: '系统到期日'
                        },
                        {
                            title: '操作',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var actions = [];
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                return actions.join('');
                            }
                        }]
                };
                $.table.init(options);
            });

            /* 租户状态显示 */
            function statusTools(row) {
                if (row.status == 1) {
                    return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
                } else {
                    return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
                }
            }

            /* 租户管理-停用 */
            function disable(id) {
                $.modal.confirm("确认要停用租户吗？", function () {
                    $.operate.post(prefix + "/changeStatus", {"id": id, "status": 1});
                })
            }

            /* 租户管理启用 */
            function enable(id) {
                $.modal.confirm("确认要启用租户吗？", function () {
                    $.operate.post(prefix + "/changeStatus", {"id": id, "status": 0});
                })
            }
        </script>
    </body>
</html>